package topology;
import org.apache.storm.task.OutputCollector;
import org.apache.storm.topology.BasicOutputCollector;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseBasicBolt;
import org.apache.storm.trident.operation.BaseFunction;
import org.apache.storm.trident.operation.TridentCollector;
import org.apache.storm.trident.tuple.TridentTuple;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

/**
 * Created by Simon on 2018/10/23.
 */
public class AppSplitBolt extends BaseFunction {
    private static final long serialVersionUID = 1L;

    @Override
    public void execute(TridentTuple tuple, TridentCollector collector) {
        String sentence = tuple.getString(0);
        for(String word: sentence.split("\t")) {
            collector.emit(new Values(word));
        }
        //只做一个输出
        System.out.println(tuple.toString());
    }

//    @Override
//    public void execute(Tuple tuple, BasicOutputCollector collector) {
//        String sentence = tuple.getString(0);
//        for(String word: sentence.split(" ")) {
//            collector.emit(new Values(word));
//        }
//        //只做一个输出
//        System.out.println(tuple.toString());
//    }
//
//    @Override
//    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
//
//    }
}